<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="${ctx}/scripts/jscalendar-1.0/calendar-blue.css" rel="stylesheet" type="text/css">
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/calendar.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/lang/calendar-en.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/calendar-setup.js"></script>
<script type="text/javascript"
	src="${ctx}/scripts/tags/unitedselect/UnitedSelect.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript"
	src="${ctx}/scripts/validation/validation.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript">
	var ACTION_URL="${ctx}/charge_charStoChoAction.do?";
		//存放控件的原始值
	var sourceValue="";

	function onSelect(thiz)
	{
		selectId = thiz.options[thiz.selectedIndex].value;
		var url =ACTION_URL+"method=unitedSelect&selectId="+selectId+"&targetId=chargeStaID";
		onChangeSelect(url,selectId,'chargeStaID');
	}

	function clearSelectTable(){
		document.frames.iChoosehouse.clearSelectTable();
	}

	function changeSelectHouseStatus(){
		if($F('chargeItemID')=="" ){
			document.frames.iChoosehouse.$('tdSelectAll').disabled=true;
			document.frames.iChoosehouse.$('buildingCellId').disabled=true;
		}else{
			document.frames.iChoosehouse.$('tdSelectAll').disabled=false;
			document.frames.iChoosehouse.$('buildingCellId').disabled=false;
		}
	}

	function getHouseIdByTable(){
		return document.frames.iChoosehouse.getHouseIdByTable();
	}

	//新增
	function add(){
		var url= ACTION_URL + "method=addFixedCho";
		var pars=$('form1').serialize()+"&houseIds="+getHouseIdByTable();
		//校验
		var isTure= $("form1").fireEvent("onSubmit");
		//ajax提交
		if(isTure && checkSelectHouse()){
			closeORopenButton();
		//			alert(url);
			var myAjax = new Ajax.Request(
		                    url,
		                    {method: 'post', parameters: pars, onComplete: 	function (result){
								var obj=findFrame('main');
								obj.reLoadIFrameList();
								closeORopenButton();
								ajaxSubmitException(result.responseText);
								windowClose();}
		                    });
		}
	}

	//验证：当某个房号、项目相同时，checkExistCharStoChoResult改为true,并提示错误信息
	var checkExistCharStoChoResult=false;
	function checkExistCharSto(houseId,houseNumber){
		if(!houseId || !houseNumber){
			return ;
		}

		var url= ACTION_URL + "method=checkExistCharStoChoFixed";
//		var pars="&houseId="+houseId+"&chargeStaID="+staId+"&chargeItemID="+itemId+"&meterId="+meterId;
		var pars=$('form1').serialize()+"&houseId="+houseId;
		//ajax提交
			var myAjax = new Ajax.Request(
		                    url,
		                    {method: 'post', parameters: pars,asynchronous:false, onComplete: 	function (result){
								if(result.responseText=="false"){
									checkExistCharStoChoResult=false;
								}else{
									alert(houseNumber+result.responseText);
									checkExistCharStoChoResult=true;
								}
								}
		                    });

	}
	function addAgain(){
		var url= ACTION_URL + "method=addFixedCho";
		var pars=$('form1').serialize()+"&houseIds="+getHouseIdByTable();
		//校验
		var isTure= $("form1").fireEvent("onSubmit");
		//ajax提交
		if(isTure && checkSelectHouse()){
			closeORopenButton();
			//	alert(url);
			var myAjax = new Ajax.Request(
		                    url,
		                    {method: 'post', parameters: pars, onComplete: 	function (result){
								var obj=findFrame('main');
								obj.reLoadIFrameList();
								closeORopenButton();
								ajaxSubmitException(result.responseText);
								document.location.reload();}
		                    });
		}
	}

	function checkSelectHouse(){
		if(getHouseIdByTable()==""){
			document.frames.iChoosehouse.$("selectSpanMessage").style.display="";
			return false;
		}else{
			document.frames.iChoosehouse.$("selectSpanMessage").style.display="none";
			return true;
		}
	}

	//关闭或打开按钮事件
	function closeORopenButton(){
		$$('window_footer').disabled= !$$('window_footer').disabled;
		$('btn1_22').disabled= !$('btn1_22').disabled;
		$('btn1_32').disabled= !$('btn1_32').disabled;
		$('btn1_42').disabled= !$('btn1_42').disabled;
	}

	function closeWin(){
		var newValue=$('form1').serialize()+getHouseIdByTable();
		if(sourceValue==newValue){
			windowClose();
		}else{
			var result=confirm("${key.tipsForCloseWindow}");
			if(result){
				add();
				return;
			}else{
				windowClose();
			}
		}
	}

	function init(){
		$('iChoosehouse').src=ACTION_URL+"method=initChooseHouse";
		sourceValue=$('form1').serialize();
	}
</script>
</head>

<body onload="init()">
<form action="" id="form1" class="required-validate" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><span class="window_head_intext"><img src="${ctx}/images/ico_Advance.gif" align="absmiddle">&nbsp;${key.addCharge}</span></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>

  <tr>
    <td class="content">
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outtable">
  <tr>
    <td>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
        <td class="aux_outtable_color">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>

		<table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
         <tr>
            <td class="aux_intable_td1">${key.chargeItem}：</td>
            <td class="aux_intable_require">
            <pms:unitedSelect
				id="chargeItemID" name="chargeItemID" actionName=""
				targetId="chargeStaID" dataList="${chargeItemList}"
				optionLabel="itemName" optionValue="keyword"
				onChange="onSelect(this);changeSelectHouseStatus();clearSelectTable();" selectText="${key.pleaseSelect}"
				className="required">
			</pms:unitedSelect></td>
            <td class="aux_intable_td1">${key.chargeSta}：</td>
            <td class="aux_intable_require"><pms:unitedSelect
				id="chargeStaID" name="chargeStaID" selectText="${key.pleaseSelect}"
				className="required" >
			</pms:unitedSelect></td>
          </tr>
          <tr id="tr01">
            <td class="aux_intable_td1">${key.startTime}：</td>
            <td class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><input name="startTime" id="startTime" type="text" class="required validate-date-yyyy-MM" afterInsert="spanstartTimeButton" value="" size="16"></td>
                <td width="4">&nbsp;</td>
                <td><img src="${ctx}/images/ico_clock.gif" name="startTimeButton" id="startTimeButton" width="20" height="20"/>
                <span id="spanstartTimeButton"></span></td>
              </tr>
            </table></td>
            <td class="aux_intable_td1">${key.endTime}</td>
            <td class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><input name="endTime" type="text" class="required validate-date-yyyy-MM great-equals-than-startTime" afterInsert="spanendTimeButton" value="" size="16"></td>
                <td width="4">&nbsp;</td>
                <td><img src="${ctx}/images/ico_clock.gif" name="endTimeButton" width="20" height="20">
                <span id="spanendTimeButton"></span>
                </td>
              </tr>
            </table></td>
          </tr>

        <tr>
          <td colspan="4" class="aux_intable_td1">
          <iframe id="iChoosehouse" frameborder="0" height="310" width="100%" scrolling="no" src=""></iframe>
          </td>
        </tr>
      </table>
	  </td>
        </tr>
      </table>
	 </td>
  </tr>
    </table></td>
	  </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2" class="window_footer">      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
		<td><table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="buttonOffLeft" id="btn1_41"></td>
            <td class="buttonOffMiddle" id="btn1_42" onClick="addAgain()" onMouseOver="btn_change_over(4)" onMouseOut="btn_change_out(4)" onblur="btn_change(4)"><img src="${ctx}/images/ico_saveandnewfile.gif" alt="" width="14" height="14" border="0" align="absbottom"> 保存并新增</td>
            <td class="buttonOffRight" id="btn1_43"></td>
          </tr>
        </table></td>
        <td class="btn_between_space">&nbsp;</td>
		  <td><table border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td class="buttonOffLeft" id="btn1_21"></td>
                <td class="buttonOffMiddle" id="btn1_22" onClick="add();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onBlur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom"> ${key.save}</td>
                <td class="buttonOffRight" id="btn1_23"></td>
              </tr>
          </table></td>
          <td class="btn_between_space"></td>
          <td><table border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td class="buttonOffLeft" id="btn1_31"></td>
                <td class="buttonOffMiddle" id="btn1_32" onClick="closeWin();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onBlur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom"> ${key.close}</td>
                <td class="buttonOffRight" id="btn1_33"></td>
              </tr>
          </table></td>
        </tr>
          </table>
      <p>&nbsp;</p></td>
  </tr>
</table>
</form>
<script type="text/javascript">

               Calendar.setup(
              {
	              inputField : "endTime", // ID of the input field
	              ifFormat : "%Y-%m", // the date format
	              button : "endTimeButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );

               Calendar.setup(
              {
	              inputField : "startTime", // ID of the input field
	              ifFormat : "%Y-%m", // the date format
	              button : "startTimeButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );


</script>
</body>
</html>